package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageDTO;
import com.sky.entity.Dish;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DishMapper {
    @Select("select count(*) from dish where category_id=#{category}")
    int countByCategoryId(Long categoryId);


    /**
     * 菜品分页
     * @param dishPageDTO
     * @return
     */
    List<DishVO> findList(DishPageDTO dishPageDTO);

    /**
     * 新增菜品
     * @param dish
     */
    @AutoFill("insert") //自动填充
    @Options(useGeneratedKeys = true,keyProperty = "id")//主键返回
    @Insert("insert into dish values (null,#{name},#{categoryId},#{price},#{image},#{description},#{status}," +
            "#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void save(Dish dish);

    /**
     * 回显菜品
     * @param id
     * @return
     */
    @Select("select d.*,c.name as categoryName from dish d left join category c on d.category_id = c.id where d.id = #{id}")
    DishVO findById(Long id);

    /**
     * 修改菜品
     * @param dish
     */
    void update(Dish dish);

    /**
     * 删除菜品
     * @param id
     */
    @Delete("delete from dish where id = #{id}")
    void delete(Long id);
}
